package com.ny.demo517;

import com.ny.demo516.Emp;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Demo {
    public static void menu(){
        System.out.println("欢迎来到员工信息管理系统");
        System.out.println("请选择你需要进行的操作");
        System.out.println("0.退出系统");
        System.out.println("1.添加员工");
        System.out.println("2.查询所有的员工");
        System.out.println("3.根据员工姓名查询");
        System.out.println("4.删除员工");
        System.out.println("5.根据员工编号查询");
        System.out.println("6.根据员工编号修改");
        System.out.println("请选择你需要进行的操作");
    }
    public static void main(String[] args) {


        TestList testList = new TestList();
        List<Emp> list = new ArrayList();

        boolean flag = true;
while (flag) {
    menu();
    Scanner scanner = new Scanner(System.in);
    int n = scanner.nextInt();
    switch (n) {
        case 0:
            flag=false;
            System.out.println("退出程序");
            break;
        case 1:

            //1 调用addEmp给list添加员工
            System.out.println("请输入员工信息");
            System.out.println("1.请输入员工编号");
            String empNumber = scanner.next();
            System.out.println("2.请输入员工姓名");
            String empName = scanner.next();
            System.out.println("3.请输入员工年龄");
            int empAge = scanner.nextInt();
//            构造方法进行赋值
            Emp addemp = new Emp(empNumber,empName,empAge);
            testList.addEmp(list,addemp);
            System.out.println(list);
            break;
        case 2:
            //2 调用findAllEmp，查询所有的员工
            testList.finfAllEmp(list);
            break;
        case 3:
            // 3 调用findEmpName 根据姓名查询

            System.out.println(" 请输入你需要查询的姓名");
            Emp emp = testList.findEmpName(list, scanner.next());
            System.out.println(emp);
            break;
        case 4:

//        4 deleteEmpNumber 根据员工编号进行删除
            System.out.println("请输入你需要删除的员工编号");
            String number = scanner.next();
            testList.deleteEmpNumber(list, number);
            break;
        case 5:
//                5 先查询，再修改
            System.out.println("请输入你需要查询的员工编号");
            String findNumber = scanner.next();
            testList.findEmpNumber(list, findNumber);
            Emp findEmp = testList.findEmpNumber(list, findNumber);
            System.out.println(findEmp);
            break;
        case 6:

            System.out.println("请输入你需要修改的员工编号");// 1001
            String updatNumber = scanner.next();
//                先查询出来
            Emp updateEmp = testList.findEmpNumber(list, updatNumber);// 把1001的员工查询出来

            System.out.println("输入你需要修改的年龄");
            int updateAge = scanner.nextInt();// 29
            updateEmp.setAge(updateAge);// 把1001 的员工棉铃修改为29
            testList.updateEmpAge(list, updateEmp);
            break;
            }
        }
    }
}
